package com.gitee.fitness.service;

import com.gitee.fitness.config.RabbitMqConfig;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;

@Service
@RabbitListener(queues = RabbitMqConfig.DEAD_LETTER_FINAL_QUEUE_NAME)
@Slf4j
public class RabbitDlxMqReceiver {

    @RabbitHandler
    public void process(Object message, Channel channel) throws Exception {
        Message message1 = (Message) message;
        String messageStr = new String(message1.getBody(), StandardCharsets.UTF_8);
        log.info("接收到死信的消息-->{}", messageStr);
        channel.basicAck(message1.getMessageProperties().getDeliveryTag(), false);
    }
}
